#include "headfiles.h"

using namespace std;

int main(int argc, char **argv) {
    if (argc != 2) {
        cout << "Usage: " << argv[0] << " infile" << endl;
        return 0;
    }

    string file_name(argv[1]);

    ifstream fs;
    fs.open(file_name.c_str(), fstream::in);
    if (!fs.is_open()) {
        cout << "File " << file_name << " open error!" << endl;
        return 1;
    }

    string str;
    fs >> str;
    int str_num = atoi(str.c_str());
    if (str_num <= 0) {
        cout << "String number " << str_num << " error!" << endl;
        return 1;
    }
    char **array = (char **)malloc(sizeof(char*) * str_num);
    if (array == NULL) {
        cout << "Allocate array buffer error!" << endl;
        return 1;
    }

    int index = 0;
    while (fs >> str) {
        if (str.empty()) {
            break;
        }

        array[index] = (char *)malloc(sizeof(char) * (str.size() + 1));
        array[index][str.size()] = '\0';
        memcpy(array[index], str.c_str(), str.size());
        ++index;
        if (index > str_num) {
            break;
        }
    }

    stringCombination((const char **)array, str_num);

    return 0;
}

